﻿using System.Windows;
using System.Windows.Controls;

namespace Sinacor.Infra.UI.Controls.SmartClient
{
	public enum RootMenuContentType
	{
		ModuleSubMenu,
		ZoomSubMenu,
		Default
	}

	public abstract class SinacorMenuItem : MenuItem
	{
		public static readonly DependencyProperty ZoomControlProperty = DependencyProperty.Register("ZoomControl", typeof(SinacorZoom), typeof(SinacorMenuItem));
		public static readonly DependencyProperty MenuTypeProperty = DependencyProperty.Register("MenuType", typeof(SinacorMenuType), typeof(SinacorMenuItem), new FrameworkPropertyMetadata(SinacorMenuType.Child));
		public static readonly DependencyProperty SubMenuContainerTypeProperty = DependencyProperty.Register("SubMenuContainerType", typeof(RootMenuContentType), typeof(SinacorMenuItem), new FrameworkPropertyMetadata(RootMenuContentType.Default));
		public static readonly DependencyProperty IconNameProperty = DependencyProperty.Register("IconName", typeof(string), typeof(SinacorMenuItem), new FrameworkPropertyMetadata(""));

		/// <summary>
		/// Retorna o Zoom Atual
		/// </summary>
		public SinacorZoom ZoomControl
		{
			get { return (SinacorZoom)GetValue(ZoomControlProperty); }
			set { SetValue(ZoomControlProperty, value);}
		}

		/// <summary>
		/// Configura o tipo do menu filho
		/// </summary>
		public SinacorMenuType MenuType
		{
			get { return (SinacorMenuType)GetValue(MenuTypeProperty); }
			set { SetValue(MenuTypeProperty, value); }
		}

		/// <summary>
		/// Define o tipo do container do submenu
		/// </summary>
		public RootMenuContentType SubMenuContainerType
		{
			get { return (RootMenuContentType)GetValue(SubMenuContainerTypeProperty); }
			set { SetValue(SubMenuContainerTypeProperty, value); }
		}

		/// <summary>
		/// Override do metodo OnApplyTemplate
		/// </summary>
		public override void OnApplyTemplate()
		{
			base.OnApplyTemplate();

			if (TemplateApplied != null)
			{
				SinacorZoom zoomControl = this.GetTemplateChild("PART_Zoom") as SinacorZoom;
				if(zoomControl != null)
					TemplateApplied(new SinacorMenuTemplateAppliedEventArgs(zoomControl));

				ZoomControl = this.GetTemplateChild("PART_Zoom") as SinacorZoom;
			}
		}

		/// <summary>
		/// Delega o evento TemplateApplied
		/// </summary>
		public delegate void TemplateAppliedHandler(SinacorMenuTemplateAppliedEventArgs e);

		/// <summary>
		/// Evento que é disparado quando o template do controle do zoom é aplicado
		/// </summary>
		public event TemplateAppliedHandler TemplateApplied;

		/// <summary>
		/// Define o nome do icone do item
		/// </summary>
		public string IconName
		{
			get { return (string)GetValue(IconNameProperty); }
			set { SetValue(IconNameProperty, value); }
		}
	}
}